package com.ozo.cloud.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ozo.cloud.common.base.model.*;
import com.ozo.cloud.common.base.model.BasePage;
import com.ozo.cloud.common.base.model.PageResult;
import com.ozo.cloud.common.base.model.ResultVO;
import com.ozo.cloud.common.log.annotation.OperateLog;
import com.ozo.cloud.system.pojo.dto.SysNoticeQueryDTO;
import com.ozo.cloud.system.pojo.dto.SysNoticeSaveDTO;
import com.ozo.cloud.system.pojo.vo.SysNoticeVO;
import com.ozo.cloud.system.service.ISysNoticeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;

/**
 * 公告 前端控制器
 *
 * @author qiangesoft
 * @version 1.0
 * @date 2024-11-19 21:58:19
 */
@Tag(name = "公告管理")
@RequiredArgsConstructor
@RestController
@RequestMapping("/notice")
public class SysNoticeController {

    private final ISysNoticeService sysNoticeService;

    @OperateLog(value = "添加公告", module = "公告")
    @SaCheckPermission("system:notice:add")
    @Operation(summary = "添加公告")
    @PostMapping("/add")
    public ResultVO<Void> add(@RequestBody @Valid SysNoticeSaveDTO saveDTO) {
        sysNoticeService.add(saveDTO);
        return ResultVO.success();
    }

    @OperateLog(value = "删除公告", module = "公告")
    @SaCheckPermission("system:notice:remove")
    @Operation(summary = "删除公告")
    @DeleteMapping("/remove")
    public ResultVO<Void> remove(@RequestBody @Valid BaseBatchDTO<Long> batchDTO) {
        sysNoticeService.remove(batchDTO);
        return ResultVO.success();
    }

    @OperateLog(value = "编辑公告", module = "公告")
    @SaCheckPermission("system:notice:edit")
    @Operation(summary = "编辑公告")
    @PutMapping("/edit")
    public ResultVO<Void> edit(@RequestBody @Validated(value = BaseValidDTO.edit.class) SysNoticeSaveDTO saveDTO) {
        sysNoticeService.edit(saveDTO);
        return ResultVO.success();
    }

    @Operation(summary = "公告分页")
    @GetMapping("/page")
    public ResultVO<PageResult<SysNoticeVO>> page(@Valid BasePage basePage, SysNoticeQueryDTO queryDTO) {
        return ResultVO.success(sysNoticeService.page(basePage, queryDTO));
    }

}